package com.example.demo.service;

import com.example.demo.client.SmQryClient;
import com.example.demo.client.evt.sysbasequery.LoginNameEvt;
import com.example.demo.client.evt.sysbasequery.UserIdEvt;
import com.example.demo.security.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author zhengmf
 * @Date 2018/12/30  14:14
 */
public abstract class BaseService {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    protected SmQryClient baseQueryClient;

    public Long getCurrentUserId() {
        LoginNameEvt loginNameEvt = new LoginNameEvt();
        loginNameEvt.setLoginName(SecurityUtils.getCurrentUserLogin().orElse(""));
        return baseQueryClient.getUserIdByLoginName(loginNameEvt).getBody();
    }

    protected String getCurrentUserAlias(){
        UserIdEvt userIdEvt = new UserIdEvt();
        userIdEvt.setUserId(getCurrentUserId());
        return baseQueryClient.getUserById(userIdEvt).getBody().getAlias();
    }
}
